﻿@page
@using Volo.Abp.Account.Web.Settings
@model Volo.Abp.Account.Web.Pages.Account.LoginModel
@inherits Volo.Abp.Account.Web.Pages.Account.AccountPage
@inject Volo.Abp.Settings.ISettingProvider SettingProvider
<h2>@L["Login"]</h2>
@if (Model.EnableLocalLogin)
{
    <form method="post">
        <input asp-for="ReturnUrl" />
        <input asp-for="ReturnUrlHash" />
        <div class="form-group">
            <label asp-for="LoginInput.UserNameOrEmailAddress"></label>
            <input asp-for="LoginInput.UserNameOrEmailAddress" class="form-control" />
            <span asp-validation-for="LoginInput.UserNameOrEmailAddress" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="LoginInput.Password"></label>
            <input asp-for="LoginInput.Password" class="form-control" />
            <span asp-validation-for="LoginInput.Password" class="text-danger"></span>
        </div>
        <div class="form-check">
            <label asp-for="LoginInput.RememberMe" class="form-check-label">
                <input asp-for="LoginInput.RememberMe" class="form-check-input" />
                @Html.DisplayNameFor(m => m.LoginInput.RememberMe)
            </label>
        </div>
        <abp-button type="button" button-type="Secondary" name="Action" value="Cancel">@L["Cancel"]</abp-button> @* TODO: Only show if identity server is used *@
        <abp-button type="submit" button-type="Primary" name="Action" value="Login">@L["Login"]</abp-button>
    </form>

    <div style="padding-top: 20px">
        @if (string.Equals(await SettingProvider.GetOrNullAsync(AccountSettingNames.IsSelfRegistrationEnabled), "true", StringComparison.OrdinalIgnoreCase))
        {
            <a href="@Url.Page("./Register", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["Register"]</a>
        }
    </div>
}

@if (Model.VisibleExternalProviders.Any())
{
    <div class="col-md-6">
        <h4>@L["UseAnotherServiceToLogIn"]</h4>
        <form asp-page="./Login" asp-page-handler="ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" asp-route-returnUrlHash="@Model.ReturnUrlHash" method="post">
            <input asp-for="ReturnUrl" />
            <input asp-for="ReturnUrlHash" />
            @foreach (var provider in Model.VisibleExternalProviders)
            {
                <button type="submit" class="btn btn-primary" name="provider" value="@provider.AuthenticationScheme" title="@L["GivenTenantIsNotAvailable", provider.DisplayName]">@provider.DisplayName</button>
            }
        </form>
    </div>
}

@if (!Model.EnableLocalLogin && !Model.VisibleExternalProviders.Any())
{
    <div class="alert alert-warning">
        <strong>@L["InvalidLoginRequest"]</strong>
        @L["ThereAreNoLoginSchemesConfiguredForThisClient"]
    </div>
}
